package cn.cj.erp.bo.system;

import cn.cj.erp.common.SearchParam;
import cn.cj.erp.common.annotation.Search;
import cn.cj.erp.common.enums.SearchType;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;


/**
 * 部门管理
 *
 * @author chenjian
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class SysDeptBo extends SearchParam {

    /** 部门ID */
    @JsonSerialize(using = ToStringSerializer.class)
    @Search
    private Long deptId;

    /** 上级部门ID */
    @NotNull(message = "上级部门不能为空")
    @JsonSerialize(using = ToStringSerializer.class)
    @Search(type = SearchType.APPLY,
            apply = "( parent_id = {} OR parent_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set({} , parent_ids)) )")
    private Long parentId;

    /** 所有的上级部门ID，以英文逗号分割 */
    private String parentIds;

    /** 部门名称 */
    @NotBlank(message = "名称不能为空")
    @Search(type = SearchType.LIKE)
    private String name;

    /** 排序号 */
    @NotNull(message = "排序号不能为空")
    private Integer orderNum;

    /** 上级部门名称 */
    private String parentName;

    /** 排除的部门id，仅搜索用 */
    private Long excludeId;

    /** 子部门 */
    private List<SysDeptBo> children = new ArrayList<>();
}
